package factory.simple.pizzastore.order;

import factory.simple.pizzastore.pizza.Pizza;

import java.io.BufferedReader;
import java.io.InputStreamReader;

/**
 * @author shenhan
 * @create 2020/3/19 16:38
 * @description
 */
public class OrderPizza {
    PizzaFactory pizzaFactory = new PizzaFactory();
    Pizza pizza = null;

    public OrderPizza(PizzaFactory pizzaFactory) {
        setPizzaFactory(pizzaFactory);
    }

    public void setPizzaFactory(PizzaFactory pizzaFactory) {
        String orderType = "";
        this.pizzaFactory = pizzaFactory;
        do {
            orderType = getType();
            pizza = this.pizzaFactory.createPizza(orderType);
            if (pizza != null) {
                pizza.prepare();
                pizza.bake();
                pizza.cut();
                pizza.box();
            } else {
                System.out.println("失败");
            }
        } while (true);
    }

    private String getType() {
        try {
            BufferedReader stin = new BufferedReader(new InputStreamReader(System.in));
            System.out.println("input info");
            String str = stin.readLine();
            return str;
        } catch (Exception e) {
            System.out.println(e.getMessage());
            return "";
        }
    }
}
